Skip to content

feat(amm): add Initialize instruction with config-gated chained calls#147

Merged
0x-r4bbit merged 1 commit into
mainfrom
feat/amm-config
Jun 18, 2026
Merged

feat(amm): add Initialize instruction with config-gated chained calls#147
0x-r4bbit merged 1 commit into
mainfrom
feat/amm-config

Conversation

@0x-r4bbit

Copy link
Copy Markdown
Collaborator

Introduce a singleton AMM configuration account, a PDA derived from the constant "CONFIG" seed, created once via a new Initialize instruction. The config stores the Token Program ID the AMM issues every chained call to, replacing the previous behavior of trusting the program owner of a caller-supplied holding.

The config account's existence is the Program's initialization gate: the chained-call instructions (new_definition, add_liquidity, remove_liquidity, swap_exact_input, swap_exact_output) now take the config as their first account, validate it against compute_config_pda(self_program_id), and read the Token Program ID from it on demand — rejecting calls until the Program is initialized. Vaults and user holdings are asserted to match the configured Token Program. sync_reserves is left ungated, as it cannot act on a pool that could not have existed before initialization.

  • amm_core: AmmConfig type, compute_config_pda/_seed, Initialize variant
  • amm: initialize.rs + config threading through chained-call instructions
  • guest: initialize instruction; config + self_program_id on gated calls
  • tests: config fixtures, init-gate unit tests, end-to-end Initialize VM test

@0x-r4bbit 0x-r4bbit requested review from 3esmit and gravityblast June 17, 2026 14:31
Introduce a singleton AMM configuration account, a PDA derived from the
constant "CONFIG" seed, created once via a new `Initialize` instruction.
The config stores the Token Program ID the AMM issues every chained call
to, replacing the previous behavior of trusting the program owner of a
caller-supplied holding.

The config account's existence is the Program's initialization gate: the
chained-call instructions (new_definition, add_liquidity, remove_liquidity,
swap_exact_input, swap_exact_output) now take the config as their first
account, validate it against `compute_config_pda(self_program_id)`, and
read the Token Program ID from it on demand — rejecting calls until the
Program is initialized. Vaults and user holdings are asserted to match the
configured Token Program. sync_reserves is left ungated, as it cannot act
on a pool that could not have existed before initialization.

- amm_core: AmmConfig type, compute_config_pda/_seed, Initialize variant
- amm: initialize.rs + config threading through chained-call instructions
- guest: initialize instruction; config + self_program_id on gated calls
- tests: config fixtures, init-gate unit tests, end-to-end Initialize VM test
@0x-r4bbit 0x-r4bbit merged commit 3624ea1 into main Jun 18, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants